VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ApiCommCtlInternetAddress"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

' ##MODULE_DESCRIPTION This class provides methods and properties for manipulating _
instances of the "Internet Address" windows custom control

Private m_hwnd As Long

Private Const IPN_FIRST = -860
Public Enum enIPAddressNotificationMessages
    IPN_FIELDCHANGED = -860
End Enum

Public Enum enIPAddressMessages
    IPM_CLEARADDRESS = 1124 ' ##  no parameters
    IPM_SETADDRESS = 1125 ' ##  lparam = TCP/IP address
    IPM_GETADDRESS = 1126 ' ##  lresult = # of non black fields.  lparam = LPDWORD for TCP/IP address
    IPM_SETRANGE = 1127 ' ##  wparam = field, lparam = range
    IPM_SETFOCUS = 1128 ' ##  wparam = field
    IPM_ISBLANK = 1129 ' ##  no parameters
End Enum

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Type NMIPADDRESS
    NMHDR_hwndFrom As Long
    NMHDR_idfrom As Long
    NMHDR_code As Long
    iField As Long
    iValue As Long
End Type

Public Enum enIPAddressFields
    IPAF_FIRST = 1
    IPAF_SECOND = 2
    IPAF_THIRD = 3
    IPAF_FOURTH = 4
End Enum

Public Property Get Blank() As Boolean

Dim lRet As Long

lRet = SendMessage(m_hwnd, IPM_ISBLANK, 0, ByVal 0&)
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiCommCtlInternetAddress:Clear", GetLastSystemError
End If
Blank = CBool(lRet)

End Property

Public Property Get ClassName() As String

    ClassName = "SysIPAddress32"
    
End Property

Public Sub Clear()

Dim lRet As Long

lRet = SendMessage(m_hwnd, IPM_CLEARADDRESS, 0, ByVal 0&)
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiCommCtlInternetAddress:Clear", GetLastSystemError
End If

End Sub

Public Property Get hWnd() As Long

    hWnd = m_hwnd
    
End Property

Public Property Let hWnd(ByVal newHwnd As Long)

    If newHwnd <> m_hwnd Then
        m_hwnd = newHwnd
    End If
    
End Property

Public Property Let IPAddress(ByVal newAddress As Long)

Dim lRet As Long

lRet = SendMessage(m_hwnd, IPM_SETADDRESS, 0, ByVal newAddress)
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiCommCtlInternetAddress:IPAddress", GetLastSystemError
End If

End Property

Public Property Get IPAddress() As Long

Dim lRet As Long
Dim lAddress As Long

lRet = SendMessage(m_hwnd, IPM_GETADDRESS, 0, lAddress)
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiCommCtlInternetAddress:IPAddress", GetLastSystemError
End If
IPAddress = lAddress

End Property

Public Sub SetFieldFocus(ByVal WhichField As enIPAddressFields)

Dim lRet As Long

lRet = SendMessage(m_hwnd, IPM_SETFOCUS, WhichField, ByVal 0&)
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiCommCtlInternetAddress:SetFieldFocus", GetLastSystemError
End If

End Sub

Public Sub SetRange(ByVal WhichField As enIPAddressFields, ByVal Lower As Byte, ByVal Upper As Byte)

Dim lRet As Long
Dim lRange As Long

lRange = APIDispenser.MakeInt(Lower, Upper)

lRet = SendMessage(m_hwnd, IPM_SETFOCUS, WhichField, ByVal lRange)
If Err.LastDllError > 0 Then
    ReportError Err.LastDllError, "ApiCommCtlInternetAddress:SetFieldFocus", GetLastSystemError
End If

End Sub


Private Sub Class_Initialize()

'\\ make sure the common controls class is initialised
Call APIDispenser.InitCommonControls(ICC_INTERNET_CLASSES)

End Sub


